const DIRECTIONS: [(isize, isize); 8] = [
    (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)
];


pub fn annotate(minefield: &[&str]) -> Vec<String> {
    let mut vec: Vec<String> = Vec::new();

    for i in 0..minefield.len() {
        let row: &str = minefield[i];
        let mut temp_row: String = String::new();
        // dbg!(&row);
        for j in 0..row.len() {
            if row.as_bytes()[j] == b'*' {
                temp_row.push('*');
                continue;
            }

            let mut mines_count: i32 = 0;
            for (dx, dy) in DIRECTIONS {
                let x = dx + i as isize;
                let y = dy + j as isize;

                if x >= 0 && x < minefield.len() as isize
                    && y >= 0 && y < row.len() as isize
                    && minefield[x as usize].as_bytes()[y as usize] == b'*' {
                    mines_count += 1;
                }
            }

            if mines_count > 0 {
                temp_row.push((b'0' + mines_count as u8) as char);
            } else {
                temp_row.push(' ')
            }
        }
        vec.push(temp_row);
        // dbg!(&vec);
    }

    vec
}